// app-header.component.ts
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { Router } from '@angular/router';
import { CommonModule } from '@angular/common';
import { AppUserInfoComponent } from '../user-info/user-info.component';
import { AuthService } from '../../services/auth.service';
@Component({
  selector: 'app-header',
  imports: [
    CommonModule,
    AppUserInfoComponent
  ],
  templateUrl: './header.component.html',
  styleUrls: ['./header.component.less']
})
export class AppHeaderComponent {
  @Input() isLoggedIn!: boolean;
  currentRoute = 'home'
  userInfo: any = {
    username: '',
    role: '',
    loginTime: ''
  }
  constructor(private router: Router, private authService: AuthService,) {
    this.currentRoute = this.router.url;
    this.userInfo = this.authService.getCurrentUser()
    console.log('this.router', this.router, this.router.url)
  }

  get showHeader(): boolean {
    return this.router.url !== '/login';
  }

  navigate(route: string) {
    this.currentRoute = `/${route}`
    this.router.navigate([`/${route}`]);
  }

  logout() {

    this.authService.clearAuthToken()

    this.userInfo = {
      username: '',
      role: '',
      loginTime: ''
    }
    this.router.navigate([`/login`]);
  }
}
